Skip to content

Warn before opening a channel whose outbound the automatic swap-out would take - #685

Merged
Jossec101 merged 2 commits into
mainfrom
feat/warn-channel-open-swap-out
Nov 25, 2026
Merged

Jossec101 merged 2 commits into
mainfrom
feat/warn-channel-open-swap-out

Conversation

@Jossec101

@Jossec101 Jossec101 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
  • Problem: opening a channel from a node with automatic liquidity management adds its capacity to the node's local balance.
    • If that leaves the balance over the node's swap-out threshold by at least a provider's min swap, AutoLiquidityManagementJob swaps the new outbound back out.
    • The swap fees are paid and the outbound the channel was meant to add is gone. The channel request form gave no hint of this.
  • Warning: on Save, ChannelRequests.razor asks for confirmation only when the open would lead to a swap-out:
    • the source node is enabled, with automatic liquidity on, a funds destination wallet and a swap budget above 0;
    • its local balance after the open (local + pending open local balance + capacity) is over MinimumBalanceThresholdSats by enough for a weighted provider the job can pick: max swaps in flight above 0, min(excess, max swap) >= min swap and, for Spark, a Spark wallet for the node (none while Spark is disabled).
    • The message gives the balance after the open, the threshold and how much of the channel would be swapped out.
    • Cold wallet: a new "Swap-out warning" modal; the request is created only on "Open anyway".
    • Hot wallet: the existing hot-wallet confirmation carries the same warning, so there's still one modal.
    • What only delays a swap is left out: swaps in flight now, the budget spent this period, a busy or full Spark wallet.
    • The balance read waits at most 5 seconds; on a timeout or error there's no warning and the open goes on as before.
  • Shared rule: SwapOutForecast holds the check. The weighted-provider rule moves to SwapProviderLimits.Weighted, used by both the forecast and AutoLiquidityManagementJob, so they can't drift.
  • Tests: 20 new SwapOutForecastTests:
    • over the threshold, exactly one min swap over, over the max swap, already over before the open;
    • landing on the threshold, staying under it, over it by less than the min swap;
    • auto liquidity off, disabled node, no funds destination wallet, swap budget of 0, no swaps in flight allowed;
    • all weights at 0 (Loop), smallest min among weighted providers, unweighted provider's min ignored;
    • provider left out with no swaps in flight allowed, a max below its min, Spark without a wallet or disabled;
    • Spark settings fallback for the min swap.
    • AutoLiquidityManagementJobTests and the full suite pass.
  • Caveats:
    • UI only: gRPC OpenChannel callers get no warning.
    • An archived Spark wallet still counts as usable (finding it needs a DB read on Save).
    • Not exercised in a running app yet.

…ould take

Opening a channel from a node with automatic liquidity management adds its capacity to the node's local balance. When
that leaves the balance over the swap-out threshold by at least a weighted provider's min swap, the next run swaps the
new outbound back out, paying swap fees. The channel request form now asks for confirmation in that case only; a hot
wallet's existing confirmation carries the same warning. The forecast shares the weighted-provider rule with
AutoLiquidityManagementJob.
The forecast now leaves out providers AutoLiquidityManagementJob can never pick: no swaps in flight allowed, a max swap
below the min swap, or Spark without a Spark wallet (Spark disabled included). A node with a swap budget of 0 gets no
warning, as every run stops at an exhausted budget. Reading the source node's balance on Save waits at most 5 seconds,
so an unreachable LND doesn't hold the button; on timeout there is no warning.
@Jossec101
Jossec101 marked this pull request as ready for review November 25, 2026 14:36
Copilot AI balanced review requested due to automatic review settings November 25, 2026 14:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the channel-opening swap-out warning changes.

No open issues 🎉

What changed in this PR

Adds a warning to the channel-opening UI when automatic liquidity management could swap out the new outbound liquidity, helping operators avoid unwanted swap fees.

Changes:

  • Adds swap-out confirmation for cold wallets and includes the warning in the existing hot-wallet confirmation.
  • Introduces a forecast helper and shares weighted-provider selection with the automatic liquidity job.
  • Adds forecast tests covering balance thresholds, provider limits, and node eligibility.
File Description
test/​NodeGuard.Tests/​Services/​SwapOutForecastTests.cs Tests forecast thresholds and provider eligibility.
src/​Services/​SwapProviderLimits.cs Centralizes weighted-provider selection and the Loop fallback.
src/​Services/​SwapOutForecast.cs Estimates new outbound liquidity subject to automatic swap-out.
src/​Pages/​ChannelRequests.razor Adds warning confirmations and a five-second balance-read timeout.
src/​Jobs/​AutoLiquidityManagementJob.cs Uses the shared weighted-provider selection rule.

Review effort: Balanced

@Jossec101
Jossec101 enabled auto-merge (squash) November 25, 2026 14:39

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Automated security review — no issues found

This PR adds a UI-only warning on the Channel Requests page: before creating an open-channel request it forecasts, via the new static SwapOutForecast, whether AutoLiquidityManagementJob would swap the new outbound back out, and gates creation behind a confirmation modal. The weighted-provider rule moved into SwapProviderLimits.Weighted, shared by job and forecast; the job-side refactor is behavior-preserving (same >0 weight filter, same all-weights-≤0 → Loop fallback). I found no way in: the only user-controlled string in the MarkupString-rendered modal body (node.Name) is HtmlEncode'd and the rest is numeric; request creation is re-entrancy-guarded (_createInFlight / pre-existing _approvalInFlight with try/finally and OkDisabled); ChannelBalanceAsync already swallows all exceptions to null, so the new TimeoutException catch is the only added error path and fails open to "no warning" as described; SparkSettings is registered in DI; no authz, fund-moving, or key-handling path changed.

Reviewed 12 files at 326095d. Nothing to report.

Not a guarantee — one diff, no knowledge of your threat model.

🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.

@markettes markettes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Jossec101
Jossec101 merged commit 09624ff into main Nov 25, 2026
7 checks passed
@Jossec101
Jossec101 deleted the feat/warn-channel-open-swap-out branch November 25, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants